/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package actions;

import beans.DisplayUsersFormBean;
import dto.JfMembers;
import dto.JfMembersHome;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import java.util.Vector;
import javax.servlet.http.HttpSession;
import moderator.ModeratorControlPanel;

/**
 *
 * @author Deena
 */
public class ModActions extends org.apache.struts.actions.DispatchAction {

    Vector<JfMembers> jfmember;
    JfMembersHome memberHome = new JfMembersHome();
    JfMembers moderator;
    moderator.ModeratorControlPanel modPanel = new ModeratorControlPanel();
    JfMembers jfmembers;
    String[] jfmembersIDs;
      JfMembers mem;

    public ActionForward Ban(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        System.out.print("\n inside ban action ");
        jfmembers = new JfMembers();
        jfmember = new Vector<JfMembers>();
        System.out.println("inside ModActions");
        DisplayUsersFormBean user = (DisplayUsersFormBean) form;
        jfmembers.setMemberId(user.getMemberId());
        jfmembers.setUsername(user.getUsername());
        System.out.print(user.getMemberId()+"BAN ACTION");
        if (modPanel.setBan(true, jfmembers)) {
            System.out.println("I am Hereeeeeeeeeeeeeee");
            jfmember = modPanel.getAllUsers();
            user.setJfmembers(jfmember);
            return mapping.findForward("done");
        } else {
            return mapping.findForward("error");
        }
    }
///////////////////////////Suspend///////////////////////////////////////////////////

    public ActionForward Suspend(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        System.out.print("\n inside suspend action ");
        jfmembers = new JfMembers();
        jfmember = new Vector<JfMembers>();
        DisplayUsersFormBean user = (DisplayUsersFormBean) form;
        jfmembers.setMemberId(user.getMemberId());
        jfmembers.setUnsuspenddate(user.getUnsuspenddate());
        System.out.print(user.getMemberId());
        if (modPanel.setSuspend(15, jfmembers, true)) {
            jfmember = modPanel.getAllUsers();
            user.setJfmembers(jfmember);
            return mapping.findForward("done");
        } else {
            return mapping.findForward("error");
        }
    }
////////////////////////////UnBan//////////////////////////////////////////////////////

    public ActionForward UnBan(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        System.out.print("\n inside ban action ");
        jfmembers = new JfMembers();
        jfmember = new Vector<JfMembers>();
        System.out.println("inside ModActions");
        DisplayUsersFormBean user = (DisplayUsersFormBean) form;
        jfmembers.setMemberId(user.getMemberId());
        jfmembers.setUsername(user.getUsername());
        System.out.print(user.getMemberId());
        if (modPanel.setBan(false, jfmembers)) {
            System.out.println("I am Hereeeeeeeeeeeeeee");
            jfmember = modPanel.getAllUsers();
            user.setJfmembers(jfmember);
            return mapping.findForward("done");
        } else {
            return mapping.findForward("error");
        }
    }

////////////////////////////UnSuspend//////////////////////////////////////////
    public ActionForward UnSuspend(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        System.out.print("\n inside suspend action ");
        jfmembers = new JfMembers();
        jfmember = new Vector<JfMembers>();
        DisplayUsersFormBean user = (DisplayUsersFormBean) form;
        jfmembers.setMemberId(user.getMemberId());
        jfmembers.setUnsuspenddate(user.getUnsuspenddate());
        System.out.print(user.getMemberId());
        if (modPanel.setSuspend(15, jfmembers, false)) {
            jfmember = modPanel.getAllUsers();
            user.setJfmembers(jfmember);
            return mapping.findForward("done");
        } else {
            return mapping.findForward("error");
        }
    }

    public ActionForward Warn(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        jfmembers = new JfMembers();
        moderator = new JfMembers();
         HttpSession session = request.getSession(false);
         mem     = (JfMembers) session.getAttribute("userBean");
        moderator.setMemberId(mem.getMemberId());
        jfmember = new Vector<JfMembers>();
        DisplayUsersFormBean user = (DisplayUsersFormBean) form;
        jfmembers.setMemberId(user.getMemberId());
        String msg = user.getMsg();
       boolean b =  modPanel.setWarn(jfmembers, moderator, msg);
       System.out.print(b);
        jfmember = modPanel.getAllUsers();
            user.setJfmembers(jfmember);
        return mapping.findForward("done");
    } 
}
